//GEN-BEGIN:Client
/**
 * This file is generated. Please do not change
 */
package co.gov.das.fotogpsserver;

import java.io.*;
import java.lang.reflect.*;
import java.util.*;

/**
 *  This class is used as an external protocol utility. It is so we don't
 *  generate as much code.
 */

public class Utility {

    /** Marker for null. Null is a type and a value together. */
    private final static short NULL_TYPE = -1;

    /** Marker for void return types. */
    public final static Object VOID_VALUE = new Object();

    /**
     * Sends return values to the client output stream.
     *
     * @param output The output stream into which all the data should be written
     * @param  returnValue The value which we should write into the stream
     * @throws IOException If an error occured while writing the results
     */
    public static void writeResults( DataOutput output, Object returnValue, int[] paramIDs) throws IOException {
        for ( int i = 0; i < paramIDs.length; i++ ) {
            writeObject(output, returnValue, paramIDs[i]);
        }
    }

    /**
     *
     * @param output
     * @param o
     * @throws java.io.IOException
     */
    public static void writeObject(DataOutput output, Object o, int id) throws IOException {
        if( o == null ) {
            // write null type to the stream
            output.writeShort( NULL_TYPE );
            return;
        }
        switch( id ) {
            case 6:
                // void
                output.writeShort(6);
                break;
            default:
                // default if a data type is not supported
                throw new IllegalArgumentException("Unsupported parameter type: " + o.getClass());
        }
    }

    /**
     *
     * @param in
     * @return
     * @throws java.io.IOException
     */
    protected static Object readObject(DataInput in) throws IOException {
        short type = in.readShort();
        Object result;
        switch (type) {
            case 1:
                // byte[]
                int a_size_1 = in.readInt();
                byte[] a_result_1 = new byte[ a_size_1 ];
                for( int a_i_1 = 0; a_i_1 < a_size_1; a_i_1++ ) {
                    a_result_1[a_i_1] = ((Byte)readObject( in )).byteValue();
                }
                result = a_result_1;

                return result;
            case 2:
                // byte
                return new Byte(in.readByte());
            case 4:
                // int
                return new Integer(in.readInt());
            case 5:
                // double
                return new Double(in.readDouble());
            case 7:
                // String
                result = in.readUTF();
                return result;
            case 8:
                // Fotografia
                co.gov.das.fotogps.movil.Fotografia b_co_gov_das_fotogps_movil_Fotografia = new co.gov.das.fotogps.movil.Fotografia();
                b_co_gov_das_fotogps_movil_Fotografia.setTamanio(in.readInt());
                b_co_gov_das_fotogps_movil_Fotografia.setFormato((String) readObject(in));
                b_co_gov_das_fotogps_movil_Fotografia.setResolucion(in.readInt());
                b_co_gov_das_fotogps_movil_Fotografia.setId(in.readInt());
                b_co_gov_das_fotogps_movil_Fotografia.setDescripcion((String) readObject(in));
                b_co_gov_das_fotogps_movil_Fotografia.setFotografia((byte[]) readObject(in));
                b_co_gov_das_fotogps_movil_Fotografia.setLatitud(in.readDouble());
                b_co_gov_das_fotogps_movil_Fotografia.setLongitud(in.readDouble());
                result = b_co_gov_das_fotogps_movil_Fotografia;

                return result;
            case NULL_TYPE: /* null */
                return null;
            default:
                throw new IllegalArgumentException(
                        "Unsupported return type (" + type + ")");
        }
    }
}
//GEN-END:Client